package com.mdframe.ai.agent.controller;

import org.springframework.ai.reader.TextReader;
import org.springframework.ai.transformer.splitter.TokenTextSplitter;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @date 2024/10/25
 */
@RestController
@RequestMapping("/store")
public class VectorStoreController {
    
    @Autowired
    private VectorStore vectorStore;
    
    @RequestMapping("/import")
    public String importFile(@RequestParam("file") MultipartFile file) {
        vectorStore.write(new TokenTextSplitter().transform(new TextReader(file.getResource()).read()));
        return "success";
    }
}
